﻿using FinalPointSet.Model.Constant.Message;
using FinalPointSet.Model.Constant;
using FinalPointSet.Model.Constants;
using FinalPointSet.Model.Manager;
using Microsoft.Win32;
using System;
using Application = System.Windows.Forms.Application;
namespace FinalPointSet.Model.Util
{
    public class PowerBootUtil
    {
        public static bool SetPowerBoot(bool isPowerBoot)
        {
            string appName = Config.APP_Name; // 你的应用程序名称或标识符  
            string appPath = Application.ExecutablePath;
            RegistryKey? rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            if (rk == null) return false;
            if (isPowerBoot)
            {
                try
                {
                    rk.SetValue(appName, appPath);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
            else
            {
                try
                {
                    rk.DeleteValue(appName, false);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
    }
}
